package com.hzdp.dao;

import com.google.common.collect.Maps;
import com.hzdp.dao.po.RivalProductPO;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * Created by lyp on 15/12/5.
 */
@Service("rivalProductDao")
public class RivalProductDao extends BaseDao {

    public void insert(RivalProductPO rivalProductPO) throws SQLException {
        insert("RivalProduct.insert",rivalProductPO);
    }

    public Integer getProductCount(int companyId, String companyCategory) throws SQLException {
        Map<String, Object> paramMap = Maps.newHashMap();
        paramMap.put("companyId",companyId);
        paramMap.put("companyCategory",companyCategory);
        return (Integer) queryObject("RivalProduct.getProductCount",paramMap);
    }

    public List<RivalProductPO> getProducts(int companyId, String companyCategory, int startIndex, int maxCount) throws SQLException {
        Map<String,Object> paramMap = Maps.newHashMap();
        paramMap.put("companyId",companyId);
        paramMap.put("companyCategory",companyCategory);
        paramMap.put("startIndex",startIndex);
        paramMap.put("maxCount",maxCount);

        return queryList("RivalProduct.getProducts",paramMap);
    }

    public boolean updateRivalCategoryId(int rivalProductId,int rivalCategoryId) throws SQLException {
        Map<String,Object> paramMap = Maps.newHashMap();
        paramMap.put("rivalProductId",rivalProductId);
        paramMap.put("rivalCategoryId",rivalCategoryId);
        return update("RivalProduct.updateRivalCategoryId",paramMap)>0;
    }

    public List<String> getAllCompanyCategories(int companyId) throws SQLException {
        return queryList("RivalProduct.getAllCompanyCategories",companyId);
    }
}
